﻿<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl" %>
<%@ Import Namespace="OAclient.Common" %>

<script type="text/javascript">
    $(function() {
        $(".datepicker").datepicker();
        $("#staffname").autocomplete({
            source: function(request, response) {
                $.ajax({
                    url: "/Home/SearchStaffFormAll",  //要查询的Action
                    type: "POST",  //Post提交
                    dataType: "json", //json格式数据，默认是text
                    data: { keyword: request.term }, //参数，不知道为什么？请指点
                    success: function(data) {
                        response($.map(data, function(item) {
                            return { label: item.text, value: item.value }; //将返回的jsonresult的属性赋值给autocomplete item
                        }))
                    }
                })
            },
            select: function(event, ui) {
                var t = ui.item.label; //'马军 事业部 员工'
                var arr = t.split(' ');
                $('#staffname').val(arr[0]);  //选中item的文本
                $('#staffid').val(ui.item.value); //选中item的值
                return false;
            },
            minLength: '0'
        })

        var options = {
            url: '/Basic/ImportStaff',
            type: 'POST',
            success: function(restag) {
                restag = restag.replace("</pre>", "");
                restag = restag.replace("<pre>", "");
                //alert(restag.res);
                restag = JSON.parse(restag);
                if (restag.res) {
                    alert("导入成功");
                }
                else {
                    alert(restag.msg);
                }
                hide_cover();
            }
        };
        $('#FrmImportStaff').ajaxForm(options);
        tableSelectOrder("#allstafflist .table_style");
    });

    function openAddStaff() {
        $.ajax({
            type: "POST",
            url: "/Basic/StaffInfo",
            success: function(data) {
                addtab("staff-1-1", "添加员工");
                $("#workarea-staff-1-1").html(data);
            }
        });
    }

    function showImportAdd() {
        $("#ImportPanel").fadeIn('slow');
    }

    function importsubmit() {
        show_cover();
        $("#ImportPanel").fadeOut('slow');
        return true;
    }

    function timeoutShadow() {
        show_cover();
        setTimeout(function() { hide_cover() }, 5000);
    }
</script>

<script type="text/javascript">
    $(function() {
        var allstafflistoptions = {
            url: '/Basic/AllStaffList',
            type: 'POST',
            success: function(data) {
                $("#workarea-staff-1").html(data);
            }
        };
        $('#frmAllStaffList').ajaxForm(allstafflistoptions);
    });

    function showStaffDetail(staffID) {
        $.ajax({
            type: "POST",
            url: "/Basic/StaffInfo",
            data: { staff_id: staffID },
            success: function(data) {
                addtab('staff-1-1', '员工信息');
                $("#workarea-staff-1-1").html(data);
            }
        })
    }
</script>

<div id="allstafflist">
    <input class="btn_style" type="button" value="添加员工" onclick="openAddStaff()" style="margin-top: 5px;" />
    <input class="btn_style" type="button" onclick='showImportAdd()' value="批量导入" />
    <a class="btn_style" href='/Basic/DeriveStaff' onclick='timeoutShadow()'>批量导出</a>
    <div id="ImportPanel" style='display: none;'>
        <%using (Html.BeginForm("ImportStaff", "Basic", FormMethod.Post, new { id = "FrmImportStaff" }))
          { %>
        <input type="file" name="importStaff" />
        <input class="btn_style" type="submit" value="导入" onclick='return importsubmit()' />
        <%} %>
    </div>
    <div style="margin: 7px 20px 2px 70px;">
        <%using (Html.BeginForm("AllStaffList", "Basic", FormMethod.Post, new { id = "frmAllStaffList" }))
          { %>
        姓名:<%=Html.TextBox("staffname")%><%=Html.Hidden("staffid")%>
        时间:<%=Html.TextBox("staffstime", "", new { @class = "datepicker" })%>
        -
        <%=Html.TextBox("staffetime", "", new { @class = "datepicker" })%>
        部门:
        <%=Html.DropDownList("dept", ViewData["list_dept"] as List<SelectListItem>, "==请选择==", null)%>
        职位:
        <%=Html.DropDownList("duty", ViewData["list_duty"] as List<SelectListItem>, "==请选择==", null)%>
        状态:<select id="staffkybz" name="staffkybz">
            <option value="" selected="selected">默认</option>
            <option value="在职">在职</option>
            <option value="离职">离职</option>
        </select>
        <input class="btn_style" type="submit" value="查询" />
        <%} %>
    </div>
    <div id="dt_allstafflist">
        <table border="0" width="100%" class="table_style" cellpadding="0" cellspacing="0">
            <thead>
                <tr>
                    <th>
                        员工编码
                    </th>
                    <th>
                        姓名
                    </th>
                    <th>
                        职位
                    </th>
                    <th>
                        部门
                    </th>
                    <th>
                        联系电话
                    </th>
                    <th>
                        创建时间
                    </th>
                    <th>
                        在职标志
                    </th>
                    <th>
                    </th>
                </tr>
            </thead>
            <tbody>
                <%
                    System.Data.DataTable dt = ViewData["dt"] as System.Data.DataTable;
                    if (dt == null || dt.Rows.Count == 0)
                    {%>
                <tr>
                    <td colspan="0" style="text-align: center;">
                        当前无数据！
                    </td>
                </tr>
                <%}
                    else
                    {
                        for (int i = 0; i < dt.Rows.Count; i++)
                        {
                %>
                <tr>
                    <td>
                        <%=dt.Rows[i]["员工编号"]%>
                    </td>
                    <td>
                        <%=dt.Rows[i]["员工名称"]%>
                    </td>
                    <td>
                        <%=dt.Rows[i]["职位名称"]%>
                    </td>
                    <td>
                        <%=dt.Rows[i]["部门名称"]%>
                    </td>
                    <td>
                        <%=dt.Rows[i]["手机"]%>
                    </td>
                    <td>
                        <%=dt.Rows[i]["创建时间"]%>
                    </td>
                    <td>
                        <%=dt.Rows[i]["在职标志"]%>
                    </td>
                    <td>
                        <a onclick="showStaffDetail(<%=dt.Rows[i]["员工编码"] %>)">详细</a>
                    </td>
                </tr>
                <%
                    }
                    } %>
            </tbody>
        </table>
    </div>
    <div id="pageLink">
        <%var pageInfo = ViewData["PagingInfo"] as PagingInfo; %>
        <%=Ajax.PageLinks(pageInfo, index => Url.Action("AllStaffList", 
            new { 
                    page = index,
                    sname = ViewData["sname"],
                    stime=ViewData["stime"], 
                    etime=ViewData["etime"],
                    dptid=ViewData["dptid"],
                    dtyid=ViewData["dtyid"],
                    skybz = ViewData["skybz"]
            }),
                        new AjaxOptions { UpdateTargetId = "allstafflist" })%>
    </div>
</div>
